"""
最长回文子串
解题思路：利用python特性 判断字符串相等
然后动态规划 1：奇数情况s是回文那如果其左右也相等就可以扩展
            2：偶数情况
"""


class Solution(object):
    def longestPalindrome(self, s):
        n = len(s)
        maxl = 0
        start = 0
        for i in range(n):
            if i - maxl >= 1 and s[i-maxl-1:i+1][::-1] == s[i-maxl-1:i+1]:
                start = i-maxl-1
                maxl += 2
            if i - maxl >= 0 and s[i-maxl:i+1][::-1] == s[i-maxl:i+1]:
                start = i-maxl
                maxl += 1
        return s[start:start+maxl]


a = Solution()
x = a.longestPalindrome("baqaaabaa")
print(x)